package start;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

public class PersonValidator implements Validator {
    public PersonValidator() {
        System.out.println("PersonValidator create..");
    }

    @Override
    public boolean supports(Class clazz) {
        System.out.println("PersonValidator supports("+clazz+")..");
        return Person.class.equals(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        System.out.println("PersonValidator validate("+target+","+errors+")..");
        ValidationUtils.rejectIfEmpty(errors, "name", "name.empty");
    }
}
